package cj.web.sc.dao;
/*
 *  
 *  
*/
import java.util.List;
import java.util.Map;

import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.SQL;
import net.paoding.rose.jade.annotation.SQLParam;
import cj.web.sc.domain.SCOrder;

/**
 * 
 * @author 
 *
 */
@DAO
public interface SCOrderDAO{
    @SQL("select * from SCOrder where id=:1")
    SCOrder queryById(int id);
    
	@SQL("UPDATE SCOrder SET expressBill=:t.expressBill,expressCom=:t.expressCom,status=:t.status,updateAt=NOW(),updateUser=:t.updateUser WHERE id=:t.id")
    void update(@SQLParam("t") SCOrder sCOrder);

	@SQL("UPDATE SCOrder SET status=:2 WHERE id=:1")
	void setStatus(int id, int status);

	@SQL("select * from SCOrder where deleteFlag=1 #if(:t.memo!=null){ AND memo LIKE '%##(:t.memo)%' } #if(:t.receiverPhone!=null){ AND receiverPhone LIKE '%##(:t.receiverPhone)%' } #if(:t.receiverName!=null){ AND receiverName LIKE '%##(:t.receiverName)%' }  #if(:t.orderNo!=null){ AND orderNo LIKE '%##(:t.orderNo)%' } #if(:t.status!=-1){ and status = :t.status} #if(:t.sellerId!=-1){ and sellerId = :t.sellerId} order by createAt desc limit :t.start,:t.length")
	List<SCOrder> queryBySellerId(@SQLParam("t")SCOrder order);

	@SQL("select count(0) from SCOrder where deleteFlag=1 #if(:t.memo!=null){ AND memo LIKE '%##(:t.memo)%' } #if(:t.receiverPhone!=null){ AND receiverPhone LIKE '%##(:t.receiverPhone)%' } #if(:t.receiverName!=null){ AND receiverName LIKE '%##(:t.receiverName)%' }  #if(:t.orderNo!=null){ AND orderNo LIKE '%##(:t.orderNo)%' } #if(:t.status!=-1){ and status = :t.status} #if(:t.sellerId!=-1){ and sellerId = :t.sellerId}")
	int sizeBySellerId(@SQLParam("t")SCOrder order);

	@SQL("UPDATE SCOrder SET expressBill=:t.expressBill,expressCom=:t.expressCom,updateAt=NOW(),updateUser=:t.updateUser WHERE id=:t.id")
	void chgXprBill(@SQLParam("t")SCOrder order);

	@SQL("UPDATE SCOrder SET deleteFlag=0,updateAt=NOW(),updateUser=:t.updateUser WHERE id=:t.id")
	void delete(@SQLParam("t")SCOrder order);

	@SQL("select a.orderNo,a.sellerName,a.discntPrice,a.receiverName,a.receiverPhone,a.receiverAddress,a.memo,a.expressCom,a.expressBill,a.status,a.wxTradeNo,a.payAt,a.payWay,group_concat(CONCAT(b.goodsItemName,b.count,'本') SEPARATOR '；') AS itemDetails from SCOrder a left join SCOrderItems b on a.id=b.orderId where a.deleteFlag=1 and a.status<>0 #if(:t.status!=-1){ and a.status = :t.status} #if(:t.sellerId!=-1){ and a.sellerId = :t.sellerId} GROUP BY a.orderNo order by a.status desc,a.createAt desc")
	List<Map> outputBySellerId(@SQLParam("t")SCOrder order);
    
	@SQL("UPDATE SCOrder SET exportFlag=1 where id in ( select id from ( select id from SCOrder where deleteFlag=1 and status<>0 #if(:t.status!=-1){ and status = :t.status} #if(:t.sellerId!=-1){ and sellerId = :t.sellerId} )a )")
	void updateOutputBySellerId(@SQLParam("t")SCOrder order);

	@SQL("SELECT COUNT(*) FROM SCOrder WHERE deleteFlag=1 AND status=2 AND orderNo=:1")
	int getOrderByNO(String orderNo);

	@SQL("UPDATE SCOrder SET status=3,expressBill=:2,expressCom=:3,updateAt=NOW() WHERE orderNo=:1")
	void updateOrderByInput(String orderNoe, String expressBill, String xps);
}